package card_discount

import (
	sqlc "bp/db/sqlc"
	"bp/internal/render"
	// sharedConv "bp/internal/rpcserver/shared/conv"
	sharedVld "bp/internal/rpcserver/shared/vld"
	cardDiscount "bp/internal/service/entity/card_discount"
	"bp/internal/util"
	cardDiscountGrpc "bp/rpc/gen/webapi/card_discount"
	"context"
)

// VldGetCardDiscountReq 验证获取卡折扣请求
func (s *CardDiscountWebApiImp) VldGetCardDiscountReq(ctx context.Context, q *sqlc.Queries, req *cardDiscountGrpc.GetCardDiscountReq) (cardDiscountID int64, err error) {
	slog := util.NewContextLogger(ctx, s.slog)
	if req.Id < 0 {
		err = render.InvalidArgumentRange("id")
		return
	}
	cardDiscountID = req.Id
	slog.Infof("card_discount_imp/query_vld.VldGetCardDiscountReq ok")
	return
}

// VldGetCardDiscountReq 验证获取卡折扣请求
func (s *CardDiscountWebApiImp) VldGetCardDiscountByOutCardIDReq(ctx context.Context, q *sqlc.Queries, req *cardDiscountGrpc.GetCardDiscountByOutCardIDReq) (outCardID int64, err error) {
	slog := util.NewContextLogger(ctx, s.slog)
	if req.OutCardId < 0 {
		err = render.InvalidArgumentRange("out_card_id")
		return
	}
	outCardID = req.OutCardId
	slog.Infof("card_discount_imp/query_vld.VldGetCardDiscountByOutCardIDReq ok")
	return
}

// VldListCardDiscountsReq 验证列出卡折扣请求
func (s *CardDiscountWebApiImp) VldListCardDiscountsReq(ctx context.Context, q *sqlc.Queries, req *cardDiscountGrpc.ListCardDiscountsReq) (ptr *cardDiscount.ListCardDiscountPtrsParam, err error) {
	slog := util.NewContextLogger(ctx, s.slog)

	if !sharedVld.IsOfferUseSceneArray(req.UseScenes, true) {
		err = render.InvalidArgumentValue("use_scenes")
		return
	}
	ptr = &cardDiscount.ListCardDiscountPtrsParam{
		UseScenes: req.UseScenes,
		Keyword:   req.Keyword,
	}
	slog.Infof("card_discount_imp/query_vld.VldListCardDiscountsReq ok")
	return
}

// VldListCardDiscountsReq 验证列出卡折扣及其统计请求
func (s *CardDiscountWebApiImp) VldListCardDiscountWithStatsReq(ctx context.Context, q *sqlc.Queries, req *cardDiscountGrpc.ListCardDiscountWithStatsReq) (ptr *cardDiscount.ListCardDiscountWithStatPtrsParam, err error) {
	slog := util.NewContextLogger(ctx, s.slog)

	if !sharedVld.IsOfferUseSceneArray(req.UseScenes, true) {
		err = render.InvalidArgumentValue("use_scenes")
		return
	}
	ptr = &cardDiscount.ListCardDiscountWithStatPtrsParam{
		UseScenes: req.UseScenes,
		Keyword:   req.Keyword,
	}
	slog.Infof("card_discount_imp/query_vld.VldListCardDiscountWithStatsReq ok")
	return
}
